472b174603c2e25521b624eba439e8e2f8bd14fc,edu-services/gradebook-service/impl/src/java/org/sakaiproject/component/gradebook/GradebookExternalAssessmentServiceImpl.java,GradebookExternalAssessmentServiceImpl,addExternalAssessment,#String#String#String#String#number#Date#String#Boolean#number#,743
Before Change
return null;
}
});
if (log.isInfoEnabled()) log.info("External assessment added to gradebookUid=" + gradebookUid + ", externalId=" + externalId + " by userUid=" + getUserUid() + " from externalApp=" + externalServiceDescription);
}
public void updateExternalAssessment(final String gradebookUid, final String externalId, final String externalUrl, final String title, final Double points, final Date dueDate, final Boolean ungraded)
After Change
addExternalAssessment(gradebookUid, externalId, externalUrl, title, points, dueDate, externalServiceDescription, ungraded, null);
}
public void addExternalAssessment(final String gradebookUid, final String externalId, final String externalUrl, final String title, final Double points,
final Date dueDate, final String externalServiceDescription, final Boolean ungraded, final Long categoryId)
throws GradebookNotFoundException, ConflictingAssignmentNameException, ConflictingExternalIdException, AssignmentHasIllegalPointsException
{
// Ensure that the required strings are not empty
if(StringUtils.trimToNull(externalServiceDescription) == null ||
StringUtils.trimToNull(externalId) == null ||
StringUtils.trimToNull(title) == null) {
throw new RuntimeException("External service description, externalId, and title must not be empty");
}
// Ensure that points is > zero
if((ungraded != null && !ungraded.booleanValue() && (points == null || points.doubleValue() <= 0))
|| (ungraded == null && (points == null || points.doubleValue() <= 0))) {
throw new AssignmentHasIllegalPointsException("Points can't be null or Points must be > 0");
}
// Ensure that the assessment name is unique within this gradebook
if (isAssignmentDefined(gradebookUid, title)) {
throw new ConflictingAssignmentNameException("An assignment with that name already exists in gradebook uid=" + gradebookUid);
}
// name cannot start with * or # as they are reserved for special columns in import/export
if(StringUtils.startsWithAny(title, new String[]{"*", "#"})) {
// TODO InvalidAssignmentNameException plus move all exceptions to their own package
throw new ConflictingAssignmentNameException("Assignment names cannot start with * or # as they are reserved");
}
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
// Ensure that the externalId is unique within this gradebook
List conflictList = (List)session.createQuery(
"select asn from Assignment as asn where asn.externalId=? and asn.gradebook.uid=?").
setString(0, externalId).
setString(1, gradebookUid).list();
Integer externalIdConflicts = conflictList.size();
if (externalIdConflicts.intValue() > 0) {
throw new ConflictingExternalIdException("An external assessment with that ID already exists in gradebook uid=" + gradebookUid);
}
// Get the gradebook
Gradebook gradebook = getGradebook(gradebookUid);
// if a category was indicated, double check that it is valid
Category persistedCategory = null;
if (categoryId != null) {
persistedCategory = getCategory(categoryId);
if (persistedCategory == null || persistedCategory.isRemoved() ||
!persistedCategory.getGradebook().getId().equals(gradebook.getId())) {
throw new InvalidCategoryException("The category with id " + categoryId +
" is not valid for gradebook " + gradebook.getUid());
}
}
// Create the external assignment
Assignment asn = new Assignment(gradebook, title, points, dueDate);
asn.setExternallyMaintained(true);
asn.setExternalId(externalId);
asn.setExternalInstructorLink(externalUrl);
asn.setExternalStudentLink(externalUrl);
asn.setExternalAppName(externalServiceDescription);
if (persistedCategory != null) {
asn.setCategory(persistedCategory);
}
//set released to be true to support selective release
asn.setReleased(true);
if(ungraded != null)
asn.setUngraded(ungraded.booleanValue());
else
asn.setUngraded(false);
session.save(asn);
return null;
}
});
log.info("External assessment added to gradebookUid={}, externalId={} by userUid={} from externalApp={}", gradebookUid, externalId, getUserUid(), externalServiceDescription);
}
public void updateExternalAssessment(final String gradebookUid, final String externalId, final String externalUrl, final String title, final Double points, final Date dueDate, final Boolean ungraded)